<template>
    <h2 style="text-align: center;">理财列表</h2>
    理财名称 <input type="text" v-model="FI_name">
    利息 <select v-model="FT_id">
            <option value=0>--请选择--</option>
            <option v-for="item in infos" :value="item.FT_id">{{ item.FT_name }}%</option>
        </select>
        <input type="button" value="查询" @click="show()">
    <table border="1">
        <tr>
            <td>理财ID</td>
            <td>理财名称</td>
            <td>年收益</td>
            <td>利息</td>
            <td>最低金额</td>
            <td>理财人次</td>
            <td>风险等级</td>
        </tr>
        <tr v-for="item in info">
            <td>{{ item.FI_id }}</td>
            <td>{{ item.FI_name }}</td>
            <td>{{ item.FI_yearmoney }}CNY</td>
            <td>{{ item.FT_name }}%</td>
            <td>{{ item.FI_minmoney }}CNY</td>
            <td>{{ item.FI_number }}</td>
            <td>{{ item.FI_grade }}风险</td>
        </tr>
    </table>
    共有{{count}}条数据，每页显示{{pagesize}}条数据，当前{{pageindex}}/{{pagecount}}页
    <a href="#" @click="updcount(1)">首页</a>
    <a href="#" @click="updcount(pageindex-1)">上一页</a>
    <a href="#" @click="updcount(pageindex+1)">下一页</a>
    <a href="#" @click="updcount(pagecount)">尾页</a>
    <br>
    <input type="text" v-model="index">
    <input type="button" value="Go" @click="updindex()">
</template>
<script setup lang="ts">
import axios from "axios"
import { ref,onMounted } from "vue"
import { useRoute } from "vue-router"
const route = useRoute()

const info=ref({
    FI_id:"",
    FI_name:"",
    FI_yearmoney:"",
    FT_id:0,
    FI_minmoney:"",
    FI_number:"",
    FI_grade:"",
    FT_name:""
})
const infos=ref({
    FT_id:0,
    FT_name:""
})
let count=0
let pageindex=1
let pagesize=2
let pagecount=0
const FI_name=ref("")
const FT_id=ref(0)

const index=ref()

const Bind=()=>{
    axios({
        url:"http://localhost:52342/api/Finan/Bind",
        method:"get",
    })
    .then((res)=>{
        infos.value=res.data
    })
    .catch((err)=>{
        console.log(err)
    })
}
onMounted(()=>{
    Bind()
    show()
})

const show =()=>{
    axios({
        url:"http://localhost:52342/api/Finan/FinanShow",
        method:"get",
        params:{
            FI_name:FI_name.value,
            FT_id:FT_id.value,
            pageindex:pageindex,
            pagesize:pagesize
        }
    })
    .then((res)=>{
        console.log(res.data)
        count=res.data.count
        pagecount=res.data.pagecount
        info.value=res.data.list
    })
    .catch((err)=>{
        console.log(err)
    })
}

const updcount=(num:any)=>{
    
    if(num>=1&&num<=pagecount){
        pageindex=num
        show()
    }else{
        alert("页码有误")
        return
    }
}

const updindex=()=>{
    if(index.value<1||index.value>pagecount){
        alert("页码有误")
        return
    }else{
        pageindex=index.value
        show()
    }
}



</script>